﻿using UnityEngine;
using System.Collections;

public class TweenCamera : TweenBase {
	public static TweenCamera fadeCamera;
	public static TweenCamera Get(){
		GameObject target = Camera.main.gameObject;
	
		if (fadeCamera == null) {
			fadeCamera = target.GetComponent<TweenCamera> ();
			if(fadeCamera == null)
				fadeCamera = target.AddComponent<TweenCamera> ();
		}
		return fadeCamera;
	}
	public Color _start;
	public Color _end;
	public void Play(Color end,float time){
		Play (Camera.main.backgroundColor, end, time);
	}
	public void Play(Color start,Color end,float time = 1){
		_start = start;
		_end = end;
		Play ();
	}
	protected override void Init ()
	{
		base.Init ();
	}
	// Update is called once per frame
	protected override void Lerp () {
		Color color = Color.Lerp (_start, _end, (Time.time - _savetime) / _time);
		Camera.main.backgroundColor = color;
	}
	protected override void PlayRest(){
		Color color = Color.Lerp (_start, _end, (Time.time - _savetime) / _time);
		Camera.main.backgroundColor = color;
	}
}
